﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Conference.Logic.Proposal;

namespace Conference.Logic.Schedule
{ 
    /// <summary>
    /// Class that represents the whole conference
    /// </summary>
    public class Event
    {
        #region Attributes
        private string name;
        private List<Track> tracks;
        #endregion

        #region Properties
        /// <summary>
        /// Get and set conference name
        /// </summary>
        public string Name
        {
            get { return this.name; }
            set 
            {
                if (!string.IsNullOrEmpty(value))
                {
                    this.name = value;
                }
                else
                {
                    throw new Exception("Invalid Conference name!");
                }
            }
        }

        /// <summary>
        /// Get a list of Track. Read only property.
        /// </summary>
        public List<Track> Tracks 
        { 
            get 
            {
                return this.tracks; 
            } 
        }
        #endregion

        #region Constructor
        /// <summary>
        /// Create a new instance of a Event object
        /// </summary>
        /// <param name="name">Conference name</param>
        public Event(string name)
        {
            try
            {
                this.Name = name;
                this.tracks = new List<Track>();
            }
            catch (Exception ex)
            {            
                throw ex;
            }
        }
        #endregion

        #region Methods
        /// <summary>
        /// Arrange all proposals according with the duration.
        /// </summary>
        /// <param name="proposals">Proposals object</param>
        public void Arrange(Proposals proposals)
        {
            try
            {
                // check if there is a list of valid proposals
                if (proposals.IsValid())
                {
                    while (proposals.HasPendingItems()) 
                    {
                        // create a new track and fill morning and afternoon sessions
                        Track track = new Track(this.tracks.Count + 1);
                        track.Moorning.Fill(proposals.GetPendings());
                        track.Afternoon.Fill(proposals.GetPendings());

                        this.tracks.Add(track);                            
                    }
                }
            }
            catch (Exception ex)
            {            
                throw ex;
            }
        }
        #endregion
    }
}
